package com.alks.function.controller.stockdept.pcfactorystockquery;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.entity.PcCuttingCollectDetail;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.dto.biocontrol.webwork.RecIoBatchRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.CuttingRceIoBackRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.CuttingRecDetRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.CuttingRecIoRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.CuttingRecTempRequest;
import com.alks.function.service.stockdept.pcfactorystockquery.ICuttingRecService;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author MS
 * @since 2024/6/28下午5:02
 */
@RestController
@ApiRestController("/pcFactorStockQuery")
@Api(value = "仓储部", tags = "仓储部-仓储工厂作业-工艺收发作业")
@Slf4j
public class ProcessRecController {
    @Autowired
    private ICuttingRecService service;

    private final String processCode = "02";
    
    @WebLogger
    @PostMapping("/processRecTempQuery")
    @ApiOperation(value = "工艺收发查询-可条件分页查询", tags = "仓储部-仓储工厂作业-工艺收发作业")
    public ResponseInfo processRecTempQuery(@RequestBody CuttingRecTempRequest request) {
        return service.cuttingRecTempQuery(request,processCode);
    }

    @WebLogger
    @PostMapping("/processRecDetQuery")
    @ApiOperation(value = "工艺收发明细查询-条件分页查询", tags = "仓储部-仓储工厂作业-工艺收发作业")
    public ResponseInfo processRecDetQuery(@RequestBody@Valid CuttingRecDetRequest request) {
        return service.cuttingRecDetQuery(request, processCode);
    }

    @WebLogger
    @PostMapping("/processInDateQuery")
    @ApiOperation(value = "日期总览查询-条件查询", tags = "仓储部-仓储工厂作业-工艺收发作业")
    public ResponseInfo processInDateQuery(@RequestParam@ApiParam(value = "日期",required = true)
                                               @DateTimeFormat(pattern = "yyyy-MM-dd")
                                               @JsonFormat(timezone = "GMT+8")
                                               LocalDate dateInfo) {
        return service.cuttingInDateQuery(dateInfo.atStartOfDay(), processCode);
    }

    @WebLogger
    @PostMapping("/processRecDetBack")
    @ApiOperation(value = "工艺收发明细回显-回显", tags = "仓储部-仓储工厂作业-工艺收发作业")
    public ResponseInfo processRecDetBack() {
        return service.cuttingRecDetBack();
    }

    @WebLogger
    @PostMapping("/processRecIoBack")
    @ApiOperation(value = "工艺收发回显-回显", tags = "仓储部-仓储工厂作业-工艺收发作业")
    public ResponseInfo processRecIoBack(@Valid@RequestBody CuttingRceIoBackRequest request) {
        return service.cuttingRecIoBack(request, processCode);
    }

    @WebLogger
    @PostMapping("/ProcessRecIoTempBack")
    @ApiOperation(value = "工艺收发表单回显-回显", tags = "仓储部-仓储工厂作业-工艺收发作业")
    public ResponseInfo ProcessRecIoTempBack(@Valid@RequestBody CuttingRceIoBackRequest request) {
        return service.cuttingRecIoTempBack(request, processCode);
    }

    @WebLogger
    @PostMapping("/processRecDetIo")
    @ApiOperation(value = "工艺收发料新增-新增", tags = "仓储部-仓储工厂作业-工艺收发作业")
    public ResponseInfo processRecDetIo(@Valid@RequestBody List<CuttingRecIoRequest> request,
                                        @RequestHeader(value = "Accept-Language", defaultValue = "zh") String language) {
        return service.cuttingRecDetIo(request, processCode,language);
    }

    @WebLogger
    @PostMapping("/processRecDetDelete")
    @ApiOperation(value = "工艺收发删除-删除", tags = "仓储部-仓储工厂作业-工艺收发作业")
    public ResponseInfo processRecDetDelete(@RequestBody PcCuttingCollectDetail request) {
        return service.cuttingRecDetDelete(request, processCode);
    }

    @WebLogger
    @PostMapping("/processBatchQuery")
    @ApiOperation(value = "批次查询-查询", tags = "仓储部-仓储工厂作业-工艺收发作业")
    public ResponseInfo processBatchQuery(@RequestBody RecIoBatchRequest request) {
        List<Map<String,Object>> batchList = service.batchQuery(request, processCode);
        return ResponseInfo.ok(batchList);
    }


}